package com.zhihao.sdk;

import java.util.HashMap;

/**
 * @author zhaosl56113
 * @description todo
 * @create 2025/7/31 09:45
 */
class Solution {
    public static int longestConsecutive(int[] nums) {
        int maxLength = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        // 查询最小值，并kv存储到map中，key是nums[i], value是index（实际上value无用）
        int min = nums[0];
        for (int i = 0; i < nums.length; i++){
            if(nums[i] < min){
                min = nums[i];
            }
            map.put(nums[i], 1);
        }
        System.out.println("min:" + min);
        // 打印map
        for (Integer key : map.keySet()) {
            System.out.println("key:" + key + " value:" + map.get(key));
        }
        // 最多有nums.size()个连续长度，所以
        int next = min;
        for(int i = 0; i < nums.length; i ++){
            boolean result = map.containsKey(next);
            if(result){
                maxLength += 1;
            }
            next++;
        }
        return maxLength;
    }

    public static void main(String[] args) {
        int[] nums = {9,1,4,7,3,-1,0,5,8,-1,6};
        System.out.println(longestConsecutive(nums));
    }
}
